home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 295_01 / bclose.c < prev    next >
Text File  |  1989-12-28  |  2KB  |  75 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "bclose.c    1.2 - 89/10/31" */
  5.  
  6. #include <errno.h>
  7. /*#include <string.h>*/
  8. #include "blkio_.h"
  9.  
  10. /*man---------------------------------------------------------------------------
  11. NAME
  12.      bclose - close a block file
  13.  
  14. SYNOPSIS
  15.      #include <blkio.h>
  16.  
  17.      int bclose(bp)
  18.      BLKFILE *bp;
  19.  
  20. DESCRIPTION
  21.      The bclose function causes any buffered data for the block file
  22.      associated with BLKFILE pointer bp to be written out, and the
  23.      block file to be closed.
  24.  
  25.      bclose will fail if one or more of the following is true:
  26.  
  27.      [EINVAL]       bp is not a valid BLKFILE pointer.
  28.      [BENOPEN]      bp is not open.
  29.  
  30. SEE ALSO
  31.      bexit, bopen, bsync.
  32.  
  33. DIAGNOSTICS
  34.      Upon successful completion, a value of 0 is returned.  Otherwise,
  35.      a value of -1 is returned, and errno set to indicate the error.
  36.  
  37. ------------------------------------------------------------------------------*/
  38. int bclose(bp)
  39. BLKFILE *bp;
  40. {
  41.     /* validate arguments */
  42.     if (!b_valid(bp)) {
  43.         errno = EINVAL;
  44.         return -1;
  45.     }
  46.  
  47.     /* check if not open */
  48.     if (!(bp->flags & BIOOPEN)) {
  49.         errno = BENOPEN;
  50.         return -1;
  51.     }
  52.  
  53.     /* synchronize file with buffers */
  54.     if (bsync(bp) == -1) {
  55.         BEPRINT;
  56.         return -1;
  57.     }
  58.  
  59.     /* close file */
  60.     if (b_uclose(bp) == -1) {
  61.         BEPRINT;
  62.         return -1;
  63.     }
  64.  
  65.     /* free memory allocated for block file */
  66.     b_free(bp);
  67.  
  68.     /* scrub slot in biob table then free it */
  69.     memset(bp, 0, sizeof(*biob));
  70.     bp->flags = 0;
  71.  
  72.     errno = 0;
  73.     return 0;
  74. }
  75.